<template>
  <Card shadow>
    <div slot="extra">
      <span>上限：60</span>
      <span>下限：20</span>
    </div>
    <div class="content">
      <div v-if="isReturn" style="position: absolute;cursor: pointer; fontSize: 0.8vw; color:#999; left: 3px; top: 0" @click="returnInit(index)">返回</div>
      <div class="info sum">
        <div class="basic">
          <h3>当天累计使用能源</h3>
          <div class="circle-bar bg1">
              <div class="circle-bar-left"></div>
              <div class="circle-bar-right"></div>
              <div class="mask">
                  <span class="percent">{{data.accumulatedEnergy.number}}</span>
              </div>
          </div>
        </div>
        <div class="chart">
          <starLine
            ref="line1"
            class="order-chart"
            :language="orderLang"
            :config="orderBarConfig"
            :chartStyle="chartStyle"
            :data="data.accumulatedEnergy.data"
          ></starLine>
        </div>
      </div>
      <div class="info relate">
        <div class="basic">
          <h3>设备能源消耗同比</h3>
          <div class="circle-bar bg2">
              <div class="circle-bar-left"></div>
              <div class="circle-bar-right"></div>
              <div class="mask">
                  <span class="percent">{{data.energySameRadio.number}}%</span>
              </div>
          </div>
        </div>
        <div class="chart">
          <starLine
            ref="line2"
            class="order-chart"
            :language="orderLang"
            :config="orderBarConfig"
            :chartStyle="chartStyle"
            :data="data.energySameRadio.data"
          ></starLine>
        </div>
      </div>
      <div class="info chain">
        <div class="basic">
          <h3>设备能源消耗环比</h3>
          <div class="circle-bar bg3">
              <div class="circle-bar-left"></div>
              <div class="circle-bar-right"></div>
              <div class="mask">
                  <span class="percent">{{data.energyChainRadio.number}}%</span>
              </div>
          </div>
        </div>
        <div class="chart">
          <starLine
            ref="line3"
            class="order-chart"
            :language="orderLang"
            :config="orderBarConfig"
            :chartStyle="chartStyle"
            :data="data.energyChainRadio.data"
          ></starLine>
        </div>
      </div>
    </div>
  </Card>
</template>

<script>
export default {
    props: {
      index: {
        default: 0,
      },
      data: {
        default: () => {}
      },
      isReturn: {
        default: true
      }
    },
    data() {
      return {
        orderLang: {
          "en-US": {
            headTitle: "user order analysis for this month",
            title: "",
          },
          "zh-CN": {
            headTitle: "本月用户订单分析",
            title: "",
          },
        },
        orderData:null,
        chartStyle: {
          height: '230px',
        },
        orderBarConfig: {
          type: "bar",
          toolbox: false,
          xAxisNameLocation: "",
          boundaryGap: true,
          yAxisNameLocation: "end",
          legend: true,
          color:[{
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: '#56e2ff' // 0% 处的颜色
              }, {
                  offset: 1, color: '#6da5fc' // 100% 处的颜色
              }]
            },{
            type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                  offset: 0, color: '#9997fb' // 0% 处的颜色
              }, {
                  offset: 1, color: '#5956c6' // 100% 处的颜色
              }],
            }],
          grid: {
            bottom: 40,
          },
          showBackground: true,
        },
      }
    },
    mounted() {

    },
    methods: {
      returnInit(i) {
        this.$emit('returnInit', i)
      }
    }
}
</script>

<style lang="less" scoped>
.ivu-card {
  width:100%;
  height:100%;
  ::v-deep .ivu-card-body {
    height: 100% !important;
  }
  ::v-deep .ivu-card-extra {
    font-size: 12px;
    span {
      margin-right: 10px;
      padding: 2px 5px;
      background-image: linear-gradient(to right, #F46564, #FF7A45);
      border-radius: 10px;
      color: #fff;
      opacity: 0.8;
      &:last-child {
        background-image: linear-gradient(to right, #7263BA, #006FBE);
      }
    }
  }
  .content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    justify-content: space-around;
    .info {
      display: flex;
      height: 30%;
      border-bottom: 1px solid #eee;
      &:last-child{
        border-bottom: 0px
      }
      .basic {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 300px;
        h3 {
          margin: 10px auto 20px;
        }
      }
      .chart {
        flex: 1;
      }
    }
  }
}
.bg1 {
  background-image: linear-gradient(#FF7A45, #FDEFE9);
}
.bg2 {
  background-image: linear-gradient(#7263BA, #EFF1FE);
}
.bg3 {
  background-image: linear-gradient(#006FBE, #E6F6FF);
}
.circle-bar {
    width: 120px;
    height: 120px;
    position: relative;
}
.circle-bar-left {
    // background-color: #e9ecef;
    width: 100px;
    height: 100px;
    clip: rect(0, 91px, auto, 0);
}
.circle-bar-right {
    // background-color: #e9ecef;
    width: 120px;
    height: 120px;
    clip: rect(0, auto, auto, 91px);
    transform: rotate(118.8deg);
}
.mask {
    width: 100px;
    height: 100px;
    background-color: #fff;
    text-align: center;
    line-height: 0.2em;
    color: rgba(0, 0, 0, 0.5);
    position: absolute;
    left: 21px;
    top: 21px;
}
.mask > span {
    display: block;
    font-size: 30px;
    line-height: 100px;
}
/*所有的后代都水平垂直居中，这样就是同心圆了*/
.circle-bar * {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
}
/*自身以及子元素都是圆*/
.circle-bar,
.circle-bar > * {
    border-radius: 50%;
}

</style>